#include <iostream>
#include <vector>
#include "util.hpp"
#include <sw/redis++/redis++.h>
using namespace std;
using sw::redis::Redis;
void test1(Redis &redis)
{
    redis.flushall();
    redis.hset("key", "hash", "1");
    redis.hset("key", {make_pair("hash1", "2"), make_pair("hash2", "3")});
    vector<pair<string, string>> fileds({make_pair("hash4", "4"),
                                         {"hash5", "5"}});
    redis.hset("key", fileds.begin(), fileds.end());

    auto value = redis.hget("key", "hash");
    if (value)
    {
        cout << "value" << value.value() << endl;
    }
    bool result = redis.hexists("key", "hash1");
    cout << "result:" << result << endl;

    long long len = redis.hdel("key", "hash5");
    cout << "len:" << len << endl;
}
void test2(Redis &redis)
{
    redis.flushall();
    redis.hset("key", "hash", "1");
    redis.hset("key", {make_pair("hash1", "2"), make_pair("hash2", "3")});
    vector<pair<string, string>> fileds({make_pair("hash4", "4"),
                                         {"hash5", "5"}});
    redis.hset("key", fileds.begin(), fileds.end());
    vector<string> values;
    auto it = back_inserter(values);
    redis.hmget("key", {"hash", "hash1", "hash2"}, it);
    PrintContainer(values);

    vector<string> filed;
    auto filedsit = back_inserter(filed);
    redis.hkeys("key", filedsit);
    PrintContainer(filed);
}

void test3(Redis &redis)
{
    redis.flushall();
    redis.hset("key", "hash", "1");
    redis.hset("key", {make_pair("hash1", "2"), make_pair("hash2", "3")});

    vector<string> container;
    auto it = back_inserter(container);
    auto Cursors = redis.hscan("key", 0, it);
    cout << "next Cursor:" << Cursors << endl;
    PrintContainer(container);
}
int main()
{
    Redis redis("tcp://127.0.0.1:6379");
    test3(redis);
    return 0;
}
